﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnityEngine;
using ZerAx.ObjectNotation;

namespace BlockOS
{
    public class EntityData
    {
        public int typeId;
        public string name;
        public float x, y, z;
        public float rx, ry, rz;

        public EntityData() { }

        public EntityData(ZonCompound zon)
        {
            name = zon.GetString("name");
            typeId = zon.GetI32("type").Value;
            SetPosition(zon.GetVec3("pos").Value);
            SetRotation(zon.GetVec3("rot").Value);
        }

        public (float, float, float) GetPosition() => (x, y, z);

        public void SetPosition(float x, float y, float z)
        {
            this.x = x;
            this.y = y;
            this.z = z;
        }

        public void SetPosition((float x, float y, float z) p) => SetPosition(p.x, p.y, p.z);

        public (float, float, float) GetRotation() => (rx, ry, rz);
        public void SetRotation(float x, float y, float z)
        {
            rx = x;
            ry = y;
            rz = z;
        }
        public void SetRotation((float x, float y, float z) r) => SetRotation(r.x, r.y, r.z);

        public void SetFromZon(ZonCompound zon)
        {
            name = zon.GetString("name");
            typeId = zon.GetI32("type").Value;
            SetPosition(zon.GetVec3("pos").Value);
            SetRotation(zon.GetVec3("rot").Value);
        }

        public ZonCompound ToZon() => new(
            ("type", typeId),
            ("name", name),
            ("pos", Zon.Vec3(x, y, z)),
            ("rot", Zon.Vec3(rx, ry, rz))
        );
    }
}
